﻿@using System.Diagnostics;
@using System.Collections;
@using System.Reflection;
@using System.Runtime.Versioning;
@using Microsoft.AspNetCore.Http
@using NewLife.Common;
@using HttpContext = NewLife.Web.HttpContext
@inject IHttpContextAccessor HttpContextAccessor

@{
    //Layout = NewLife.Cube.Setting.Current.Layout;

    ViewBag.Title = "服务器变量列表";
    var httpContext = HttpContextAccessor.HttpContext;
    var req = httpContext.Request;
    // ASP.NET Core中没有ServerVariables的对应实现，需要换一种方式，可以在HttpContext.Request.Headers中获取
}

<div class="card card-custom gutter-b">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover table-condensed">
                <tr>
                    <th class="text-dark text-hover-primary font-size-h5 font-weight-bold" colspan="6">
                        服务器变量列表
                    </th>
                </tr>
                <tr>
                    <th>名称</th>
                    <th>数值</th>
                </tr>
                @foreach (var kv in req.Headers)
                {
                    var v = kv.Value.ToString();
                    v = v.Replace("\r\n", "</br>");
                    var key = kv.Key;
                    if (key.EqualIgnoreCase("HTTP_COOKIE")) { v = v.Replace(";", "</br>"); }
                    <tr>
                        <td>@key</td>
                        <td style="max-width:600px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" data-toggle="tooltip" data-placement="top" title="@Html.Raw(v)">@Html.Raw(v)</td>
                    </tr>
                }
            </table>
        </div>
    </div>
</div>

<div class="card card-custom">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover table-condensed">
                <tr>
                    <th class="text-dark text-hover-primary font-size-h5 font-weight-bold" colspan="6">
                        Request变量列表&nbsp;&nbsp;&nbsp;&nbsp;@req.GetType().FullName
                    </th>
                </tr>
                <tr>
                    <th>名称</th>
                    <th>数值</th>
                </tr>
                @foreach (var pi in req.GetType().GetProperties())
                {
                    var type = pi.PropertyType;
                    if (pi.GetIndexParameters().Length > 0 || (type != typeof(String)
                                                               && type != typeof(Uri)
                                                               && type != typeof(PathString)
                                                               && type != typeof(HostString)
                                                               && !typeof(Boolean).IsAssignableFrom(type)
                                                               && !typeof(String).IsAssignableFrom(type)))
                    {
                        continue;
                    }
                    var v = req.GetValue(pi) + "";
                    v = v.Replace("\r\n", "</br>");
                    <tr>
                        <td>@pi.Name</td>
                        <td>@Html.Raw(v)</td>
                    </tr>
                }
            </table>
        </div>
    </div>
</div>
